"use strict"
//查询在线信息
const mvc = require("cosjs.mvc");
exports.query = async function () {
    const sid = this.get('sid', 'int');
    let item = mvc.model.mongo('item', sid);
    let option = { "multi": true, "dataType": "array", "limit": 300000, 'batchSize': 3000 };
    let query = { 'bag': 50 };
    let ret = await item.find(query, option);
    let result = {}
    let coll = [];

    for (let i = 0; i < ret.length; ++i) {
        let card = ret[i];
        if (!result[card.id]) {
            result[card.id] = {};
            result[card.id].id = card.id;
            result[card.id].num = 0;
            result[card.id].lv = 0;
            result[card.id].slv = 0;
            result[card.id].blv = 0;
            result[card.id].maxLv = 0;
            result[card.id].maxSlv = 0;
            result[card.id].maxBlv = 0;
            coll.push(result[card.id]);
        }
        result[card.id].num++;
        if (card.lv) {
            result[card.id].lv += card.lv;
            result[card.id].maxLv += Math.max(card.lv, result[card.id].maxLv);
        }
        if (card.slv) {
            result[card.id].slv += card.slv;
            result[card.id].maxSlv += Math.max(card.slv, result[card.id].maxSlv);
        }
        if (card.blv) {
            result[card.id].blv += card.blv;
            result[card.id].maxBlv += Math.max(card.blv, result[card.id].maxBlv);
        }
    }
    return coll;
}